package com.wtwd.campus.send;

import com.wtwd.campus.common.Constants;
import com.wtwd.campus.entity.Command;
import com.wtwd.campus.entity.DeviceAlarm;
import com.wtwd.campus.entity.MqGeneralSet;
import com.wtwd.campus.entity.MqMessage;
import com.wtwd.campus.utils.UnicodeUtil;
import org.apache.commons.lang.StringUtils;

public class SetAlarmClockSender implements Sender {
    @Override
    public Command dealMessage(MqMessage mqMessage) {
        MqGeneralSet mqGeneralSet = (MqGeneralSet) mqMessage.getObject();
        DeviceAlarm alarm = (DeviceAlarm) mqGeneralSet.getValue();
        String name ="";
        if(!StringUtils.isBlank(alarm.getName())){
            name = UnicodeUtil.gbEncoding(alarm.getName());
        }
        //指令拼接
        String commandContent= "*".concat(Constants.MANUFACTURER_NAME).concat(",").concat(alarm.getImei()).concat(",").concat(Constants.ALARM_CLOCK).concat(",")
                .concat(alarm.getCommandNumber()).concat(",").concat(String.valueOf(alarm.getSequence())).concat(",")
                .concat(name).concat(",").concat(alarm.getTime()).concat(",").concat(alarm.getRepeatTime())
                .concat(",").concat(String.valueOf(alarm.getFlag())).concat("#");
        Command command=new Command();
        command.setImei(alarm.getImei());
        command.setCommandNumber(alarm.getCommandNumber());
        command.setStatus(Constants.COMMAND_NEED_SAVE);
        command.setContent(commandContent);
        command.setCmd(Constants.ALARM_CLOCK);
        command.setSequence(alarm.getSequence());
        return command;
    }
}
